package com.lam.code.service.impl;

import com.lam.code.base.BaseServiceImpl;
import com.lam.code.entity.User;
import com.lam.code.mapper.UserMapper;
import com.lam.code.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lam
 * @description 用户service实现
 * @date 2019/12/22 22:57
 */
@Service
@Slf4j
public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements UserService {
    private static final String encryptSalt = "F1339dEhdnnE23#221";

    @Override
    public List<String> getPermissionByUseId(String userId) {
        //TODO 权限缓存
        return new ArrayList<>();
    }

    /**
     * 获取数据库中保存的用户信息，主要是加密后的密码
     * @param userCode username
     * @return User
     */
    @Override
    public User getUserInfoByCode(String userCode) {
        //TODO 加用户信息缓存
        User user = new User();
        user.setId("1");
        user.setUsername("admin");
        user.setEncryptPwd(new Sha256Hash("123456", encryptSalt).toHex());
        return user;
    }

    @Override
    public User getUserInfoById(String userId) {
        //TODO 加用户信息缓存
        User user = new User();
        user.setId("1");
        user.setUsername("admin");
        user.setEncryptPwd(new Sha256Hash("123456", encryptSalt).toHex());
        return user;
    }

    @Override
    public void deleteLoginUserInfo(String useId) {
        log.info("delete login info..userId:{}", useId);
    }
}
